﻿using System;

namespace Wrox.ProCSharp.Generics
{
  class Program
  {
    static void Main()
    {
      IIndex<Rectangle> rectangles = RectangleCollection.GetRectangles();
      //因为IIndex接口是协变的(out)，所以可以把返回值赋予IIndex<Shape>类型的变量
      IIndex<Shape> shapes = rectangles;

      for (int i = 0; i < shapes.Count; i++)
      {
        Console.WriteLine(shapes[i]);
      }


      IDisplay<Shape> shapeDisplay = new ShapeDisplay();
      //因为IDisplay是抗变的(in)，所以可以把结果赋予 IDisplay<Rectangle>
      IDisplay<Rectangle> rectangleDisplay = shapeDisplay;
      rectangleDisplay.Show(rectangles[0]);

    }

  }
}
